﻿using Core.Framework;
using DotNetty.Transport.Channels.Groups;
using iTool.ClusterComponent;
using Orleans.Streams;
using System;
using System.Threading.Tasks;

namespace DotNetty.Framework.ExtendChannelOfClient
{
    public class ReceiveChannelNotifyObserver : SubscribeQueueHandler<string>
    {
        public IChannelGroup iChannelGroup { get; set; }

        public ReceiveChannelNotifyObserver(string topic, IChannelGroup iChannelGroup) : base(topic, AppSetting.QueueConnectorStreamNamespace)
        {
            this.iChannelGroup = iChannelGroup;
        }

        public override Task OnErrorAsync(Exception ex)
        {
            Console.WriteLine("OnErrorAsync:" + ex.Message);
            return Task.CompletedTask;
        }

        public async override Task OnMessageAsync(string message, StreamSequenceToken token)
        {
            await this.iChannelGroup.WriteAndFlushAsyncOfBinaryAsync(message);
        }
    }
}
